package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;


import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.StationNearBean;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;

/**
 * Copyright (c)2020
 * author: Clark
 * created on:2020年10月9日 16点06分
 * description: App出行规划共交模块
 */
public class TripPlanStationListAdapter extends RecyclerView.Adapter<TripPlanStationListAdapter.TripPlanStationListHolder> {
    private Context mContext;
    private List<StationNearBean> viewData = new ArrayList<>();
    private BaseInterface baseInterface;
    private int busNum;

    public interface BaseInterface {
        public void onClick(View view, StationNearBean bean);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }

    public TripPlanStationListAdapter(Context context) {
        mContext = context;
    }

    @Override
    public TripPlanStationListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.tripplan_bus_item, parent, false);
        return new TripPlanStationListHolder(view);
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.tripplan_bus_item;
    }

    @Override
    public void onBindViewHolder(TripPlanStationListHolder holder, int position) {
//        holder.blurringView.setBlurredView();

//        loadItemData(position, holder.binding);
        {

            StationNearBean bean = viewData.get(position);
            holder.subway_station_name.setText(bean.getStationName());
            holder.subway_station_address.setText(bean.getStationAddress());

            ArrayList<String> busList = new ArrayList<>();
            for (int i = 0; i < viewData.get(position).getLabelList().size(); i++) {
                busList.addAll(viewData.get(position).getLabelList());
            }

            holder.subway_station_go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    baseInterface.onClick(v, bean);
                }
            });
        }

    }

    //    private void loadItemData(int position, TripplanBusItemBinding binding) {
//        if (viewData != null) {
//
//            QueryNearStandbyRes.BusSiteListBean bean=viewData.getBusSiteList().get(position);
//            binding.subwayStationName.setText(bean.getStand_name());
//            binding.subwayStationAddress.setText(bean.getRoad());
//
//            ArrayList<QueryNearStandbyRes.BusSiteListBean.BusInfosBean> busList=new ArrayList<>();
//            for(int i=0;i<viewData.getBusSiteList().get(position).getBusInfos().size();i++){
//                busList.add(viewData.getBusSiteList().get(position).getBusInfos().get(i));
//            }
//           binding.labels.setLabels(busList, new LabelsView.LabelTextProvider<QueryNearStandbyRes.BusSiteListBean.BusInfosBean>() {
//               @Override
//               public CharSequence getLabelText(TextView label, int position, QueryNearStandbyRes.BusSiteListBean.BusInfosBean data) {
//                   return data.getLine_name();
//               }
//           });
//
//            binding.labels.clearAllSelect();
//
//            binding.labels.setOnLabelClickListener(new LabelsView.OnLabelClickListener() {
//                @Override
//                public void onLabelClick(TextView label, Object data, int position) {
//                    Toast.makeText(mContext,"you click the"+position+"label",Toast.LENGTH_LONG).show();
//                }
//            });
//        }
//
//    }
    @Override
    public int getItemCount() {
        if (viewData == null) {
            return 0;
        }
        return viewData.size();

    }

    public void setViewData(List<StationNearBean> viewData) {
        this.viewData.clear();
        this.viewData.addAll(viewData);

    }

    //    public static class TripPlanBusListHolder extends BaseHolder {
//        private TripplanBusItemBinding binding;
//
//        public static TripPlanBusListHolder creat(ViewGroup parent) {
//            TripplanBusItemBinding binding =
//                    TripplanBusItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
//
//            return new TripPlanBusListHolder(binding);
//        }
//        public TripPlanBusListHolder(TripplanBusItemBinding binding) {
//            super(binding.getRoot());
//            this.binding = binding;
//        }
//
//    }
    public static class TripPlanStationListHolder extends RecyclerView.ViewHolder {

        private final TextView subway_station_name;
        private final TextView subway_station_go;
        private final TextView subway_station_address;


        public TripPlanStationListHolder(View view) {
            super(view);
            subway_station_name = view.findViewById(R.id.subway_station_name);
            subway_station_go = view.findViewById(R.id.subway_station_go);
            subway_station_address = view.findViewById(R.id.subway_station_address);
        }
    }

}
